package tabdulin.sms.contacts;

import javax.swing.AbstractListModel;

/**
 * @author Talgat Abdulin
 *
 */
public class ContactListModel extends AbstractListModel implements ContactListListener {
    private static final long serialVersionUID = 1L;
    private final ContactList contactList;
    
    public ContactListModel(ContactList contactList) {
        super();
        this.contactList = contactList;
        contactList.addListener(this);
    }
    
    @Override
    public Object getElementAt(int index) {
        return contactList.get(index);
    }

    @Override
    public int getSize() {
        return contactList.size();
    }

    @Override
    public void update() {
        fireContentsChanged(this, 0, getSize() - 1);
    }
    
    public void addElement(Contact newContact) {
        contactList.add(newContact);
    }
    
    public void removeElementAt(int index) {
        contactList.remove(index);
    }
    
}
